package com.apop.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @ClassName ThreadPoolConfig
 * @Author Jiayi Zheng
 * @Date 2021/12/22 11:29
 * @Description: 线程池配置
 * @Version V1.0
 */
@Configuration
@EnableAsync
public class ThreadPoolConfig {
    private int corePoolSize = 3;
    private int maxPoolSize = 3;
    private int queueCapacity = 10;
    private int keepAlive = 100;

    @Bean
    public TaskExecutor taskExecutor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSize);
        executor.setMaxPoolSize(maxPoolSize);
        executor.setQueueCapacity(queueCapacity);
        executor.setThreadNamePrefix("thread-");
        executor.setKeepAliveSeconds(keepAlive);
        return executor;
    }
}
